package phoenix.web.test_objects.data_providers;

import java.util.ArrayList;

import org.testng.TestException;
import org.testng.TestNGException;

import phoenix.core.PhoenixManager;
import phoenix.core.base.extensions.TestBaseExt;
import phoenix.core.data_models.TestUserDataModel;

/**
 * Class contains test data for Payment page
 */
public class UserPageDataProviders extends TestBaseExt
{
	public UserPageDataProviders(PhoenixManager p_phoenix)
	{
		super(p_phoenix);
	}

	public Object[][] interactionDataMale()
	{
		TestUserDataModel p_userSender = manager.testUser();
		TestUserDataModel p_userRecipient = null;

		if (manager.isFGF())
		{
			p_userRecipient = manager.db().getUser("c1318746c49c11e38e3e68b599be7074");
		}
		else if (manager.isMD())
		{
			p_userRecipient = manager.db().getUser("39e8659b7af611e49ef5441ea14ed80c");
		}
		else if (manager.isNF())
		{
			p_userRecipient = manager.db().getUser("6b2ee67b853a11e49ef5441ea14ed80c");
		}
		else
		{
			p_userRecipient = manager.db().getUserBy(testModel().getSiteName(), manager.testUser().defineMembershipStatus("female"), "female", "3000");
		}

		if (p_userSender.getId() == null || p_userRecipient.getId() == null)
		{
			throw new TestNGException("Unable to fill users");
		}

		TestUserDataModel p_user = manager.backend().editPage().getUserModel(p_userRecipient);

		if (p_user.getGender().equals("male"))
		{
			p_userRecipient.setGender("female");
			manager.backend().editPage().setUserModel(p_userRecipient);
		}

		manager.backend().searchPage().unsetUserAsHot(p_userRecipient);
		manager.backend().searchPage().unsetUserAsScammer(p_userRecipient);
		manager.backend().searchPage().verifyPayStatus(p_userRecipient);

		return new Object[][]

		{
				{ p_userSender, p_userRecipient }, // male -> female
		};
	}

	public Object[][] messengerDataMale()
	{
		TestUserDataModel[] p_userRecipient = {
				manager.db().getUserBy(testModel().getSiteName(), manager.testUser().defineMembershipStatus("female"), "female"),
				manager.db().getUserBy(testModel().getSiteName(), manager.testUser().defineMembershipStatus("male"), "male")
		};

		if (p_userRecipient[0].getId() == null || p_userRecipient[1].getId() == null)
		{
			throw new TestNGException("Unable to fill users");
		}

		return new Object[][]
		{
				{ p_userRecipient }, // male -> female
		};
	}

	public Object[][] messengerOpenData()
	{
		TestUserDataModel[] p_userRecipient = {
				manager.db().getUserBy(testModel().getSiteName(), manager.testUser().defineMembershipStatus("male"), "male", "2000"),
				manager.db().getUserBy(testModel().getSiteName(), manager.testUser().defineMembershipStatus("male"), "male", "3000"),
		};

		if (p_userRecipient[0].getId() == null || p_userRecipient[1].getId() == null)
		{
			throw new TestNGException("Unable to fill users");
		}

		if (p_userRecipient[0].getId().toString().equals(p_userRecipient[1].getId().toString()))
		{
			throw new TestNGException("Duplicated profiles added");
		}

		manager.web().myAccountPage().disableMatchNotifications(p_userRecipient[1]);
		manager.web().myAccountPage().disableMatchNotifications(p_userRecipient[0]);

		return new Object[][]
		{
				{ p_userRecipient }, // male -> female
		};
	}

	public Object[][] interactionDataFemale()
	{
		TestUserDataModel p_userSender = manager.testUser();
		TestUserDataModel p_user = manager.db().getUserBy(testModel().getSiteName(), 1, "male", "1000");

		manager.backend().searchPage().verifyPayStatus(p_user);
		manager.backend().searchPage().unsetUserAsScammer(p_userSender);

		return new Object[][]
		{
				{ p_userSender, p_user }, // female -> male
		};
	}

	public Object[][] interactionDataFemaleB2B()
	{
		TestUserDataModel p_userSender = db().getUser("c1318746c49c11e38e3e68b599be7074");
		TestUserDataModel p_userRecipientMale = manager.testUser();

		return new Object[][]
		{
				{ p_userSender, p_userRecipientMale }, // female -> male
		};
	}

	public Object[][] paymentHotUserData()
	{
		TestUserDataModel p_userHot = db().getUserBy(testModel().getSiteName(), 1, "male", "3000");

		if (p_userHot == null)
		{
			throw new TestNGException("Can't load users in data provider");
		}

		// Verify membership status at backend
		manager.backend().searchPage().verifyPayStatus(p_userHot);
		manager.backend().searchPage().setUserAsHot(p_userHot);

		return new Object[][]
		{
				{ p_userHot },
		};
	}

	public Object[][] paymentReceiveChatData()
	{
		String p_messageKey = "Hello, what do you: "
				+ randomizer().getRandomString(10)
				+ randomizer().getRandomInt(1, 1000);
		TestUserDataModel p_userSender = manager.testUser();
		TestUserDataModel p_userRecipient = null;

		if (manager.isMD())
		{
			p_userRecipient = db().getUser("75be20fe7ca911e49ef5441ea14ed80c");
		}
		else if (manager.isNF())
		{
			p_userRecipient = db().getUser("4ea70bfd820c11e49ef5441ea14ed80c");
		}
		else
		{
			p_userRecipient = db().getUserBy(testModel().getSiteName(), manager.testUser().defineMembershipStatus("female"), "female", "1000");
		}

		if (p_userSender == null || p_userRecipient == null)
		{
			throw new TestNGException("Can't load users in data provider");
		}

		// Verify membership status at backend
		manager.backend().searchPage().verifyPayStatus(p_userRecipient);
		manager.backend().searchPage().unsetUserAsHot(p_userRecipient);

		return new Object[][]
		{
				{ p_messageKey, p_userSender, p_userRecipient },
		};
	}

	public Object[][] paymentAnswerChatData()
	{
		String p_messageKey = "Hello, what do you: "
				+ randomizer().getRandomString(10)
				+ randomizer().getRandomInt(1, 1000);
		TestUserDataModel p_userSender = manager.testUser();
		TestUserDataModel p_userRecipient = null;

		if (manager.isMD())
		{
			p_userRecipient = db().getUser("137eee86820411e49ef5441ea14ed80c");
		}
		else
		{
			p_userRecipient = db().getUserBy(testModel().getSiteName(), manager.testUser().defineMembershipStatus("female"), "female", "1500");
		}

		if (p_userSender == null || p_userRecipient == null)
		{
			throw new TestNGException("Can't load users in data provider");
		}

		// Verify membership status at backend
		manager.backend().searchPage().verifyPayStatus(p_userRecipient);

		return new Object[][]
		{
				{ p_messageKey, p_userSender, p_userRecipient },
		};
	}

	public Object[][] paymentFreeCommunicationData()
	{

		TestUserDataModel p_userPaidFeatures = db().getUserByMembershipStatus(testModel().getSiteName(), 4);
		TestUserDataModel p_userHot = db().getUserBy(testModel().getSiteName(), 1, "male", "500");

		if (p_userPaidFeatures == null || p_userHot == null)
		{
			throw new TestNGException("Can't load users in data provider");
		}

		// Verify membership status at backend
		manager.backend().searchPage().verifyPayStatus(p_userPaidFeatures);
		manager.backend().searchPage().verifyPayStatus(p_userHot);
		manager.backend().searchPage().setUserAsHot(p_userHot);
		manager.web().myAccountPage().disableMatchNotifications(p_userPaidFeatures);
		manager.web().myAccountPage().disableMatchNotifications(p_userHot);

		return new Object[][]
		{
				{ p_userPaidFeatures, p_userHot },
		};
	}

	public Object[][] paymentTwoMessagesData()
	{
		String p_messageKey = "Hello, what do you: "
				+ randomizer().getRandomString(10)
				+ randomizer().getRandomInt(1, 1000);
		TestUserDataModel p_userSender = manager.testUser();

		TestUserDataModel p_userRecipient = null;

		if (manager.isMD())
		{
			p_userRecipient = db().getUser("d389f48d7ca811e49ef5441ea14ed80c");
		}
		else if (manager.isNF())
		{
			p_userRecipient = db().getUser("e05f935c820b11e49ef5441ea14ed80c");
		}
		else
		{
			p_userRecipient = db().getUserBy(testModel().getSiteName(), manager.testUser().defineMembershipStatus("female"), "female", "6000");
		}

		if (p_userRecipient == null)
		{
			throw new TestException("Unable to load users in data provider");
		}

		manager.backend().searchPage().verifyPayStatus(p_userRecipient);

		return new Object[][]
		{
				{ p_messageKey, p_userSender, p_userRecipient },
		};
	}

	public Object[][] paymentSpecialDeliveryData()
	{
		TestUserDataModel p_userRecipient = db().getUserBy(testModel().getSiteName(), 2, "male", "2000");

		if (manager.isMD())
		{
			p_userRecipient = db().getUser("6162a55a7c9a11e49ef5441ea14ed80c");
		}
		else if (manager.isNF())
		{
			p_userRecipient = db().getUser("9d903756844a11e49ef5441ea14ed80c");
		}

		// Verify membership status at backend
		manager.backend().searchPage().verifyPayStatus(p_userRecipient);

		if (p_userRecipient.getId() == null)
		{
			throw new TestException("Unable to load users");
		}

		return new Object[][]
		{
				{ p_userRecipient },
		};
	}

	@Deprecated
	public Object[][] paymentRedirectionsDataFiveMessages()
	{
		String p_messageKey = "Hello, what do you: "
				+ randomizer().getRandomString(10)
				+ randomizer().getRandomInt(1, 1000);

		TestUserDataModel p_userSender = testUser();

		ArrayList<TestUserDataModel> p_testUserDataModels = new ArrayList<>();

		if (manager.isMD())
		{
			p_testUserDataModels.add(db().getUser("75e51dae7aef11e49ef5441ea14ed80c"));
			p_testUserDataModels.add(db().getUser("c65d156c7aeb11e49ef5441ea14ed80c"));
			p_testUserDataModels.add(db().getUser("fc2762447aea11e49ef5441ea14ed80c"));
			p_testUserDataModels.add(db().getUser("9f8c9a1b7ae911e49ef5441ea14ed80c"));
			p_testUserDataModels.add(db().getUser("ed8f79dc7ae211e49ef5441ea14ed80c"));
			p_testUserDataModels.add(db().getUser("2d7b65147ae211e49ef5441ea14ed80c"));
		}
		else if (manager.isNF())
		{
			p_testUserDataModels.add(db().getUser("3016c2c6844411e49ef5441ea14ed80c"));
			p_testUserDataModels.add(db().getUser("65b669e8844411e49ef5441ea14ed80c"));
			p_testUserDataModels.add(db().getUser("a7ed969f844411e49ef5441ea14ed80c"));
			p_testUserDataModels.add(db().getUser("dbd90100844411e49ef5441ea14ed80c"));
			p_testUserDataModels.add(db().getUser("47161c80844511e49ef5441ea14ed80c"));
			p_testUserDataModels.add(db().getUser("893bc065844511e49ef5441ea14ed80c"));
		}
		else
		{
			p_testUserDataModels.add(db().getUserBy(testModel().getSiteName(), manager.testUser().defineMembershipStatus("male"), "male", "1500"));
			p_testUserDataModels.add(db().getUserBy(testModel().getSiteName(), manager.testUser().defineMembershipStatus("male"), "male", "1600"));
			p_testUserDataModels.add(db().getUserBy(testModel().getSiteName(), manager.testUser().defineMembershipStatus("male"), "male", "1700"));
			p_testUserDataModels.add(db().getUserBy(testModel().getSiteName(), manager.testUser().defineMembershipStatus("male"), "male", "1800"));
			p_testUserDataModels.add(db().getUserBy(testModel().getSiteName(), manager.testUser().defineMembershipStatus("male"), "male", "1900"));
			p_testUserDataModels.add(db().getUserBy(testModel().getSiteName(), manager.testUser().defineMembershipStatus("male"), "male", "2000"));
		}

		if (p_testUserDataModels.size() != 6 && p_testUserDataModels.get(5) != null)
		{
			throw new TestNGException("Can't load users from db");
		}
		// Check for duplicated profiles
		for (int i = 0; i < p_testUserDataModels.size(); i++)
		{
			for (int j = 0; j < p_testUserDataModels.size(); j++)
			{
				if (i != j && p_testUserDataModels.get(i).getId().toString().equals(p_testUserDataModels.get(j).getId().toString()))
				{

					Integer p_time = 100;
					Integer p_actualTime = 350;
					Integer time_value = p_time + p_actualTime;

					TestUserDataModel p = db()
							.getUserBy(testModel().getSiteName(), manager.testUser().defineMembershipStatus("female"), "female", time_value.toString());

					Integer p_attempts = 0;
					while (p.getId().toString().equals(p_testUserDataModels.get(j).getId().toString()))
					{
						p_attempts++;
						p = db().getUserBy(testModel().getSiteName(), manager.testUser().defineMembershipStatus("female"), "female", time_value.toString());
						time_value = time_value + 100;

						if (p_attempts == 5)
						{
							throw new TestNGException("Unable to find unique profile after 5 attempts");
						}
					}
					p_testUserDataModels.add(p);
					p_testUserDataModels.remove(j);
				}
			}
		}

		return new Object[][] {
				{ p_messageKey, p_userSender, p_testUserDataModels },
		};
	}

	public Object[][] paymentFreeCommunicationMessengerData()
	{
		String p_messageKey = "Hello, what do you: "
				+ randomizer().getRandomString(10)
				+ randomizer().getRandomInt(1, 1000);
		TestUserDataModel p_userSender = manager.testUser();
		TestUserDataModel p_userRecipient = db().getUserBy(testModel().getSiteName(), 2, "male", "2000");

		if (manager.isMD())
		{
			p_userRecipient = db().getUser("bf1ddcb3797a11e49ef5441ea14ed80c");
		}
		else if (manager.isNF())
		{
			p_userRecipient = db().getUser("c9b7722e844911e49ef5441ea14ed80c");
		}

		if (p_userSender == null || p_userRecipient == null)
		{
			throw new TestNGException("Can't load users in data provider");
		}

		// Verify membership status at backend
		manager.backend().searchPage().verifyPayStatus(p_userRecipient);

		return new Object[][]
		{
				{ p_messageKey, p_userSender, p_userRecipient },
		};
	}

	public Object[][] userWithPhotoData()
	{
		TestUserDataModel p_user = manager.db().getUser("37ad716125c711e49ef5441ea14ed80c");

		return new Object[][]
		{
				{ p_user }
		};
	}

	public Object[][] messageFromUserProfile()
	{
		TestUserDataModel p_userSender = db().getUserBy(testModel().getSiteName(), manager.testUser().defineMembershipStatus("female"), "female");

		return new Object[][]
		{
				{ p_userSender },
		};
	}

	public Object[][] messengerDeliveryStatus()
	{
		TestUserDataModel p_userSender = db().getUserBy(testModel().getSiteName(), 2, "male");

		return new Object[][] { { p_userSender }, };
	}

	public Object[][] messengerNotificationFreeData()
	{
		TestUserDataModel[] p_userRecipients = null;

		if (manager.isMD())
		{
			p_userRecipients = new TestUserDataModel[] {
					db().getUser("ed18fa637afe11e49ef5441ea14ed80c"),
					db().getUser("067f465a7afe11e49ef5441ea14ed80c"),
					db().getUser("75a149617afc11e49ef5441ea14ed80c"),
			};
		}
		else if (manager.isNF())
		{
			p_userRecipients = new TestUserDataModel[] {
					db().getUser("29783859844311e49ef5441ea14ed80c"),
					db().getUser("5ecf9124844311e49ef5441ea14ed80c"),
					db().getUser("a30a0a89844311e49ef5441ea14ed80c"),
			};
		}
		else
		{
			p_userRecipients = new TestUserDataModel[] {
					db().getUserBy(testModel().getSiteName(), manager.testUser().defineMembershipStatus("female"), "female", "10000"),
					db().getUserBy(testModel().getSiteName(), manager.testUser().defineMembershipStatus("female"), "female", "20000"),
					db().getUserBy(testModel().getSiteName(), manager.testUser().defineMembershipStatus("female"), "female", "30000"),
			};
		}

		if (p_userRecipients[0].getId() == null || p_userRecipients[1].getId() == null || p_userRecipients[2].getId() == null)
		{
			throw new TestNGException("Unable to fill users");
		}
		else if (!p_userRecipients[0].getId().equals(p_userRecipients[1].getId().toString()) && p_userRecipients[1].getId().equals(p_userRecipients[2].getId()))
		{
			throw new TestNGException("Duplicated users");
		}

		// expected position in list after click
		int p_Barby_third = 3;
		int p_Barby_second = 2;
		int p_Barby_first = 1;

		ArrayList<Integer> fixtureArrayPosition = new ArrayList<Integer>();
		fixtureArrayPosition.add(0, p_Barby_third);
		fixtureArrayPosition.add(1, p_Barby_second);
		fixtureArrayPosition.add(2, p_Barby_first);

		if (fixtureArrayPosition.size() != 3)
		{
			throw new TestNGException("Unable to fill fixture");
		}

		return new Object[][]
		{
				{ p_userRecipients, fixtureArrayPosition },
		};
	}

	@Deprecated
	public Object[][] messengerNotificationPaidData()
	{
		TestUserDataModel[] p_userRecipients = null;

		if (manager.isMD())
		{
			p_userRecipients = new TestUserDataModel[] {
					db().getUser("ed18fa637afe11e49ef5441ea14ed80c"),
					db().getUser("067f465a7afe11e49ef5441ea14ed80c"),
					db().getUser("75a149617afc11e49ef5441ea14ed80c"),
			};
		}
		else if (manager.isNF())
		{
			p_userRecipients = new TestUserDataModel[] {
					db().getUser("fe258912844911e49ef5441ea14ed80c"),
					db().getUser("367ab1e9844a11e49ef5441ea14ed80c"),
					db().getUser("6a54113f844a11e49ef5441ea14ed80c"),
			};
		}
		else
		{
			p_userRecipients = new TestUserDataModel[] {
					db().getUserBy(testModel().getSiteName(), manager.testUser().defineMembershipStatus("female"), "female", "1000"),
					db().getUserBy(testModel().getSiteName(), manager.testUser().defineMembershipStatus("female"), "female", "2000"),
					db().getUserBy(testModel().getSiteName(), manager.testUser().defineMembershipStatus("female"), "female", "3000"),
			};
		}

		if (p_userRecipients[0].getId() == null || p_userRecipients[1].getId() == null || p_userRecipients[2].getId() == null)
		{
			throw new TestNGException("Unable to fill users");
		}

		// Expected position
		int p_Barby_third = 3;
		int p_Barby_second = 2;
		int p_Barby_first = 1;

		ArrayList<Integer> fixtureArrayPosition = new ArrayList<Integer>();
		fixtureArrayPosition.add(0, p_Barby_third);
		fixtureArrayPosition.add(1, p_Barby_second);
		fixtureArrayPosition.add(2, p_Barby_first);

		return new Object[][]
		{
				{ p_userRecipients, fixtureArrayPosition },
		};
	}

	public Object[][] creditsRedirectionsDataB2C()
	{
		String p_messageKey = "Hello, what do you: "
				+ randomizer().getRandomString(10)
				+ randomizer().getRandomInt(1, 1000);

		String p_subjectKey = "subject";

		TestUserDataModel p_userSender = db().getUser("edfab66f382511e49ef5441ea14ed80c");

		TestUserDataModel p_userRecipient = manager.testUser();

		if (p_userSender == null || p_userRecipient == null)
		{
			throw new TestNGException("Can't load users in data provider");
		}

		return new Object[][]
		{
				{ p_messageKey, p_subjectKey, p_userSender, p_userRecipient },
		};
	}

	public Object[][] paymentRedirectionsSendMessageData()
	{
		String p_messageKey = "Hello, what do you: "
				+ randomizer().getRandomString(10)
				+ randomizer().getRandomInt(1, 1000);

		TestUserDataModel p_userSender = manager.testUser();
		TestUserDataModel p_userRecipient = db().getUserBy(testModel().getSiteName(), manager.testUser().defineMembershipStatus("female"), "female", "1000");

		if (p_userSender == null || p_userRecipient == null)
		{
			throw new TestNGException("Can't load users in data provider");
		}

		manager.backend().searchPage().verifyPayStatus(p_userRecipient);

		return new Object[][]
		{
				{ p_messageKey, p_userSender, p_userRecipient },
		};
	}

	public Object[][] paymentRedirectionsPhotosData()
	{
		TestUserDataModel p_userWithPhotos = db().getUserBy("benaughty", "female", 2);

		if (p_userWithPhotos == null)
		{
			throw new TestNGException("Can't load user in data provider");
		}

		return new Object[][]
		{
				{ p_userWithPhotos },
		};
	}

	public Object[][] paymentRedirectionsFeaturesData()
	{
		TestUserDataModel p_userFeatures = db().getUserByMembershipStatus(testModel().getSiteName(), 4);
		TestUserDataModel p_userHot = db().getUserBy(testModel().getSiteName(), manager.testUser().defineMembershipStatus("female"), "female", "6000");

		if (p_userFeatures.getId() == null || p_userHot.getId() == null)
		{
			throw new TestNGException("Can't load users in data provider: userFeatures => [" + p_userFeatures + "], userHot => [" + p_userHot + "]");
		}

		manager.backend().searchPage().verifyPayStatus(p_userFeatures);
		manager.backend().searchPage().verifyPayStatus(p_userHot);
		manager.backend().searchPage().setUserAsHot(p_userHot);
		manager.backend().searchPage().unsetUserAsScammer(p_userFeatures);

		return new Object[][]
		{
				{ p_userFeatures, p_userHot },
		};
	}

	public Object[][] paymentAnswerData()
	{
		String p_messageKey = "Hello, what do you: "
				+ randomizer().getRandomString(10)
				+ randomizer().getRandomInt(1, 1000);
		TestUserDataModel p_userSender = manager.testUser();
		TestUserDataModel p_userRecipient = db().getUser("ed41a2687b0311e49ef5441ea14ed80c");

		if (p_userSender == null || p_userRecipient == null)
		{
			throw new TestNGException("Can't load users in data provider");
		}

		// Verify membership status at backend
		manager.backend().searchPage().verifyPayStatus(p_userRecipient);
		manager.backend().searchPage().unsetUserAsHot(p_userRecipient);

		return new Object[][]
		{
				{ p_messageKey, p_userSender, p_userRecipient },
		};
	}
}
